package com.employment.config;

import com.mybatisflex.core.FlexGlobalConfig;
import com.mybatisflex.core.audit.AuditManager;
import com.mybatisflex.core.audit.ConsoleMessageCollector;
import com.mybatisflex.core.audit.MessageCollector;
import com.mybatisflex.spring.boot.MyBatisFlexCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * MyBatis Flex配置类
 * 
 * @author Employment System
 * @since 1.0.0
 */
@Configuration
public class FlexConfig {

    /**
     * MyBatis-Flex全局配置
     */
    @Bean
    public MyBatisFlexCustomizer mybatisFlexCustomizer() {
        return new MyBatisFlexCustomizer() {
            @Override
            public void customize(FlexGlobalConfig globalConfig) {
                // 配置审计功能（字段自动填充）
                AuditManager.setAuditEnable(true);
                AuditManager.setMessageCollector(consoleMessageCollector());
                
                // 开启逻辑删除
                globalConfig.setLogicDeleteColumn("deleted");
                globalConfig.setNormalValueOfLogicDelete("0");
                globalConfig.setDeletedValueOfLogicDelete("1");
                
                // 关闭横幅显示
                globalConfig.setPrintBanner(false);
            }
        };
    }

    /**
     * 控制台SQL打印配置
     */
    @Bean
    public MessageCollector consoleMessageCollector() {
        return new ConsoleMessageCollector();
    }
}